package com.ruoyi.standingbook.v2toilet.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.v2toilet.domain.bo.V2ToiletImpDetailBo;
import com.ruoyi.standingbook.v2toilet.domain.vo.V2ToiletImpDetailVo;
import com.ruoyi.standingbook.v2toilet.service.IToiletImpDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * V2市政公厕管养
 *
 * @author cc
 * @date 2023-06-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/toiletv2/toiletImpDetailV2")
public class V2ToiletImpDetailController extends BaseController {

    private final IToiletImpDetailService iToiletImpDetailService;

    /**
     * 查询V2市政公厕管养列表
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:list")
    @GetMapping("/list")
    public TableDataInfo<V2ToiletImpDetailVo> list(V2ToiletImpDetailBo bo, PageQuery pageQuery) {
        return iToiletImpDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出V2市政公厕管养列表
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:export")
    @Log(title = "V2市政公厕管养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(V2ToiletImpDetailBo bo, HttpServletResponse response) {
        List<V2ToiletImpDetailVo> list = iToiletImpDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "V2市政公厕管养", V2ToiletImpDetailVo.class, response);
    }

    /**
     * 获取V2市政公厕管养详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:query")
    @GetMapping("/{id}")
    public R<V2ToiletImpDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iToiletImpDetailService.queryById(id));
    }

    /**
     * 新增V2市政公厕管养
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:add")
    @Log(title = "V2市政公厕管养", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody V2ToiletImpDetailBo bo) {
        return toAjax(iToiletImpDetailService.insertByBo(bo));
    }

    /**
     * 修改V2市政公厕管养
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:edit")
    @Log(title = "V2市政公厕管养", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody V2ToiletImpDetailBo bo) {
        return toAjax(iToiletImpDetailService.updateByBo(bo));
    }

    /**
     * 删除V2市政公厕管养
     *
     * @param ids 主键串
     */
    @SaCheckPermission("toiletv2:toiletImpDetailV2:remove")
    @Log(title = "V2市政公厕管养", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iToiletImpDetailService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
